package com.example.sprintboot.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.math.BigDecimal;

@Data
@TableName("order_item")
public class OrderItem {
    @TableId(value = "item_id", type = IdType.AUTO)
    private Integer itemId;
    @TableField("order_id")
    private Integer orderId;
    @TableField("product_id")
    private Integer productId;
    @TableField("product_name")
    private String productName;
    @TableField("product_price")
    private BigDecimal productPrice;
    private Integer quantity;
    @TableField(exist = false)
    private BigDecimal totalPrice;
    public void calculateTotalPrice() {
        if (productPrice != null && quantity != null) {
            this.totalPrice = productPrice.multiply(BigDecimal.valueOf(quantity));
        } else {
            this.totalPrice = BigDecimal.ZERO;
        }
    }
}
